package org.example;

public class isHappy {
    class Solution {

        public int bitSum(int n) {
            int Sum = 0;
            while(n != 0) {
                int t = n % 10;
                Sum += t * t;
                n /= 10;
            }
            return Sum;
        }

        public boolean isHappy(int n) {
            int slow = n,fast = n;
            do{
                slow = bitSum(slow);
                fast = bitSum(bitSum(fast));
            }while(slow != fast);
            return slow == 1;
        }
    }
}
